tools: reduce copies b/w ocaml Strings and Bytes
authorMarcello Seri <marcello.seri@citrix.com>
Thu, 5 Apr 2018 10:40:21 +0000 (11:40 +0100)
committerWei Liu <wei.liu2@citrix.com>
Fri, 6 Apr 2018 08:29:21 +0000 (09:29 +0100)
commit2d6a8daef89cfc5caa1adad4643d6329c4842194
treefe494fd6fdb884ee5c18fa388c2f51d67a8e445e
parentd96f17f50c621be30e5c73da9317c91d8cbbf3e1
tools: reduce copies b/w ocaml Strings and Bytes

When xenstore was ported to the new safe-string interface, it mostly
happened by making copyies of string into bytes and back.  The ideal
fix would be to rewrite all of the relevant interfaces to be uniformly
using bytes, but in the meanwhile we can improve the code by using unsafe
conversion functions (see
 https://caml.inria.fr/pub/docs/manual-ocaml/libref/Bytes.html#3_Unsafeconversionsforadvancedusers).

In most cases we own the bytes that we are converting to string, or we
immediately make copies that we then mutate, or we use them immutably
as payloads for writes. In all these cases it is safe to use the unsafe
functions and prevent a copy.

This patch updates the code to use the unsafe conversions where possible.

Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
Reviewed-by: Christian Lindig <christian.lindig@citrix.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
tools/ocaml/libs/xb/xb.ml
tools/ocaml/xenstored/logging.ml
tools/ocaml/xenstored/stdext.ml
tools/ocaml/xenstored/utils.ml